package com.lin.service;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.lin.dao.PsHouseDao;
import com.lin.domain.*;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Isolation;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;

@Service
public class PsHouseServiceImpl implements PsHouseService {
    @Resource
    private PsHouseDao psHouseDao;

    @Override
    public List<SysOrg> getSysOrgList() {
        return psHouseDao.getSysOrgList();
    }

    @Override
    public List<HouseDoor> getHouseByPapersCode(String papersCode) {
        return psHouseDao.getHouseByPapersCode(papersCode);
    }

    @Override
    public HouseDoorInfo getHouseInfoByHouseId(String houseId) {
        return psHouseDao.getHouseInfoByHouseId(houseId);

    }

    @Override
    public List<HouseRepairLog> getHouseRepairLogListByHouseId(Long houseId) {
        return psHouseDao.getHouseRepairLogListByHouseId(houseId);
    }


    @Override
    public List<ProjectInfo> getProjectList() {
        return psHouseDao.getProjectList();
    }

    @Transactional(propagation = Propagation.REQUIRED, isolation = Isolation.DEFAULT, timeout = 36000, rollbackFor = Exception.class)
    @Override
    public Long saveRepairUser(HashMap<String, Object> map) {
        Long aLong = psHouseDao.saveRepairUser(map);
        String tel = (String) map.get("tel");
        String houseId = (String) map.get("houseId");
        psHouseDao.updateHouseDoor(tel, houseId);
        return aLong;
    }

    @Override
    public Page<HouseDoor> getHouseByPapersCodePage(String papersCode, String invoiceNo, int pageNum, int pageSize) {
        PageHelper.startPage(pageNum, pageSize);
        Page<HouseDoor> houseByPapersCodePage = psHouseDao.getHouseByPapersCodePage(papersCode, invoiceNo);
        return houseByPapersCodePage;
    }


    @Override
    public Page<HouseRepairLog> getHouseRepairLogListPageByHouseId(String houseId, int pageNum, int pageSize) {
        PageHelper.startPage(pageNum, pageSize);
        Page<HouseRepairLog> houseRepairLogPage = psHouseDao.getHouseRepairLogListPageByHouseId(houseId);
        return houseRepairLogPage;
    }
}
